# Maintainer: Ray Donnelly <mingw.android@gmail.com>

_realname=glpk
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=5.0
pkgrel=1
pkgdesc="GNU Linear Programming Kit: solve LP, MIP and other problems (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64' 'clang32')
url="https://www.gnu.org/software/glpk/glpk.html"
license=('spdx:GPL-3.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-gmp")
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-cc")
options=('staticlibs' 'strip')
source=("https://ftp.gnu.org/gnu/glpk/glpk-${pkgver}.tar.gz"
        'timeval-64bit.patch'
        'fix-platform-check.patch')
sha256sums=('4a1013eebb50f728fc601bdd833b0b2870333c3b3e5a816eeba921d95bec6f15'
            '2d09d58139fd85d695f5b2933ec750adf0b438a1e9a53dee1b264b80dd2e0f6a'
            '9a866c1e14f7a200a46b83c78b9f2d207167633e6ef0c51341008f07ee677d8a')

prepare () {
  cd "${srcdir}/glpk-${pkgver}"
  patch -p1 -i "${srcdir}/timeval-64bit.patch"
  patch -Np1 -i "${srcdir}/fix-platform-check.patch"
  sed -i "s|-version-info|-no-undefined -version-info|g" src/Makefile.am
  autoreconf -vfi
}

build() {
  [[ -d "${srcdir}/build-${MSYSTEM}" ]] && rm -rf "${srcdir}/build-${MSYSTEM}"
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-shared \
    --enable-static \
    --with-gmp \
    --with-gnu-ld

  make
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"
  make check
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make DESTDIR="${pkgdir}" install

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
